//
//  YCMessageCell.m
//  YCSchool
//
//  Created by gmall on 16/5/9.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  消息cell

#import "YCMeMessageCell.h"

@interface YCMeMessageCell()

/** 背景视图  */
@property (nonatomic, strong) UIView *bgView;

/** 头像 */
@property (nonatomic, weak) UIImageView *iconImageView;
/** 图片 */
@property (nonatomic, weak) UIImageView *rightImageView;
/** 昵称  */
@property (nonatomic, weak) UILabel *nikerNameLabel;
/** 内容  */
@property (nonatomic, weak) UILabel *contentLabel;
/** 时间 */
@property (nonatomic, weak) UILabel *timeLabel;

@end

@implementation YCMeMessageCell

//- (void)setItemModel:(YCMeMessageModel *)itemModel
//{
//    _itemModel = itemModel;
//    if (!itemModel.desc) {
//        self.bgView.backgroundColor = itemModel.isSelected ? [UIColor yc_colorWithUInt:0xd0d0d0]:[UIColor whiteColor];
//        self.selectedImageView.hidden = itemModel.isSelected ? NO : YES;
//        self.detailButton.hidden = itemModel.isSelected ? YES : NO;
//    }
//    self.classLabel.textColor = [_itemModel.className isEqualToString:@"VIP班"]?[UIColor yc_colorWithUInt:0xff4055]:[UIColor blackColor];
//    
//    self.iconImageView.image = [UIImage imageNamed:itemModel.icon];
//    self.classLabel.text = itemModel.className;
//    self.classDescLabel.text = itemModel.classMethod;
//}

/**
 *  快速创建cell
 *
 *  @param tableView cell所在的表
 *  @param indexPath cell位置
 *  @param action    点击详细介绍按钮的操作
 *
 *  @return 返回cell对象
 */
+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView withIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"meMessageCell";
    YCMeMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[YCMeMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor clearColor];
    }
    return cell;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.bgView];
        
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20);
            make.right.equalTo(self.contentView).offset(-20);
            make.top.equalTo(self.contentView).offset(5);
            make.bottom.equalTo(self.contentView).offset(-5);
        }];
    }
    return self;
}

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 10;
        _bgView.layer.masksToBounds = YES;
        
        UIImageView *iconImageView = [[UIImageView alloc] init];
        iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        iconImageView.image = [UIImage imageNamed:@"特惠班"];
        self.iconImageView = iconImageView;
        
        // 昵称
        UILabel *nikerNameLabel = [[UILabel alloc] init];
        nikerNameLabel.font = [UIFont boldSystemFontOfSize:14];
        nikerNameLabel.textAlignment = NSTextAlignmentLeft;
        nikerNameLabel.text = @"左萌主";
        nikerNameLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
        self.nikerNameLabel = nikerNameLabel;
        
        // 内容
        UILabel *contentLabel = [[UILabel alloc] init];
        contentLabel.font = [UIFont systemFontOfSize:13];
        contentLabel.textAlignment = NSTextAlignmentLeft;
        contentLabel.text = @"满满的都是套路";
        contentLabel.textColor = [UIColor yc_colorWithUInt:0x808080];
        self.contentLabel = contentLabel;
        
        // 时间
        UILabel *timeLabel = [[UILabel alloc] init];
        timeLabel.font = [UIFont systemFontOfSize:8];
        timeLabel.textAlignment = NSTextAlignmentLeft;
        timeLabel.text = @"3小时前";
        timeLabel.textColor = [UIColor yc_colorWithUInt:0x999999];
        self.timeLabel = timeLabel;
        
        UIImageView *rightImageView = [[UIImageView alloc] init];
        rightImageView.contentMode = UIViewContentModeScaleAspectFill;
        rightImageView.clipsToBounds = YES;
        rightImageView.image = [UIImage imageNamed:@"mf_bg_img"];
        self.rightImageView = rightImageView;
        
        [_bgView addSubview:iconImageView];
        [_bgView addSubview:nikerNameLabel];
        [_bgView addSubview:contentLabel];
        [_bgView addSubview:rightImageView];
        [_bgView addSubview:timeLabel];
        // 布局
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(_bgView).offset(10);
            make.width.height.equalTo(@50);
        }];
        
        [nikerNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_bgView).offset(14);
            make.left.equalTo(iconImageView.mas_right).offset(20);
        }];
        
        [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(nikerNameLabel);
            make.top.equalTo(nikerNameLabel.mas_bottom).offset(20);
        }];
        
        [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_bgView).offset(-10);
            make.centerY.equalTo(_bgView);
            make.width.height.equalTo(@80);
        }];
        
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bgView).offset(10);
            make.bottom.equalTo(_bgView).offset(-12);
        }];
        
    }
    return _bgView;
}


@end
